package com.bac.rentmap.ad.flat.search;

import java.util.List;

import javax.cache.Cache;

import org.springframework.beans.factory.annotation.Required;

import com.google.appengine.api.memcache.MemcacheService;

public class CachingFlatAdKeySearcher implements FlatAdKeySearcher {
    private FlatAdKeySearcher flatAdKeySearcher;
    private MemcacheService cache;

    @Override
    public List<Long> search(SearchParameters searchParameters) {
        @SuppressWarnings("unchecked")
        List<Long> res = (List<Long>) cache.get(searchParameters);
        if(res != null)
            return res;
        res = flatAdKeySearcher.search(searchParameters);
        cache.put(searchParameters, res);
        return res;
    }

    @Required
    public void setFlatAdKeySearcher(FlatAdKeySearcher flatAdKeySearcher) {
        this.flatAdKeySearcher = flatAdKeySearcher;
    }
    @Required
    public void setCache(MemcacheService cache) {
        this.cache = cache;
    }
}
